/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.permission.controller;

import java.util.List;
import queenb.net.entitybean.Q350;
import queenb.net.util.QueenbConstant;
import queenb.web.controller.QueenbController;
import queenb.web.permission.store.Q350Store;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class Q350Controller extends QueenbController {

    private int pq350;
    private String qv351;
    private Q350Store q350Store;
    private boolean flag;

    public Q350Controller() {
        getKapiMenu().setAdmin(true);
        getKapiMenu().setMainmenu2("m221");
        Object pq350Object = getRequest().getParameter("pq350");
        if (getRequest().getParameter("action") != null) {
            String action = getRequest().getParameter("action");
            if (action.equals("edit")) {
                pq350 = Util.parseInt(pq350Object.toString());
                flag = true;
                getListQ350All();
            } else {
                flag = false;
            }
        }
    }

    public List<Q350> getListQ350All() {
        try {
            q350Store = new Q350Store();
            List<Q350> listQ350All = q350Store.getListQ350All(getLogin().getModule(), pq350, 99);
            if (listQ350All.size() > 0) {
                this.qv351 = listQ350All.get(0).getQv351();
            }
            return listQ350All;
        } catch (Exception ex) {
            return null;
        }

    }

    public void updateQ350() {
        q350Store = new Q350Store();
        if (flag == true) {
            int count = q350Store.updateQ350(pq350, 7, 99, qv351, getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        } else {
            int count = q350Store.updateQ350(pq350, 7, 99, qv351, getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        }
        sendRedirect("Q350.jsp");
    }
    
    public int deleteQ350(int id)
    {
        q350Store = new Q350Store();
         if (id != 0) {
            int rows = 0;
            rows = q350Store.deleteQ350(id, getLogin().getUserName());
            return rows;
        } else {
            return 0;
        }
    }

    /**
     * @return the pq350
     */
    public int getPq350() {
        return pq350;
    }

    /**
     * @param pq350 the pq350 to set
     */
    public void setPq350(int pq350) {
        this.pq350 = pq350;
    }

    /**
     * @return the qv351
     */
    public String getQv351() {
        return qv351;
    }

    /**
     * @param qv351 the qv351 to set
     */
    public void setQv351(String qv351) {
        this.qv351 = qv351;
    }
}
